/*
 * CiudadelaNet.java
 *
 * Created on March 3, 2008, 2:46 PM
 */
package visualizer;

import Bloques.Segment;
import Util.ParseXMLFile;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

/**
 *
 * @author  emmanuel
 */
public class CiudadelaNet extends javax.swing.JPanel {

    private Segment segments[];
    Thread find;
    FindEvent x;

    /** Creates new form CiudadelaNet */
    public CiudadelaNet() {
        segments = new Segment[1000];
        x = new FindEvent(this, segments);
        find = new Thread(x);
        find.start();

    //initComponents();

    //repaint();
    }
    Image offscreen;
    Dimension offscreensize;
    Graphics offgraphics;

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponents(g);
        if (segments[0] == null) {
            new ParseXMLFile(segments, g);
        }

        System.out.println("Inside");
        int index = 0;
        Dimension d = size();
        if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) {

            offscreen = createImage(d.width, d.height);
            offscreensize = d;
            offgraphics = offscreen.getGraphics();
        }

        offgraphics.setColor(getBackground());
        offgraphics.fillRect(0, 0, d.width, d.height);

           


        while (segments[index] != null) {
            segments[index].paintSegment(offgraphics);
            segments[index].paintObjects(offgraphics); 
            index++;
        }
        g.drawImage(offscreen, 0, 0, null);



    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    private void loadNetwork() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
